package com.test.zhangxin.jianpin.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.test.zhangxin.jianpin.R;
import com.test.zhangxin.jianpin.bean.Template;

import java.util.List;

/**
 * Created by admin on 2017/6/16.
 */

public class RvVerAdapter extends RecyclerView.Adapter<RvVerAdapter.RVHolder> {
    private Context mContext;
    private List<Template> mTemplates;

    public RvVerAdapter(Context context, List<Template> templates) {
        mContext = context;
        mTemplates = templates;
    }

    @Override
    public RvVerAdapter.RVHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_rv_ver, parent, false);
        RVHolder holder = new RVHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RvVerAdapter.RVHolder holder, int position) {
        holder.bindData(position);
    }

    @Override
    public int getItemCount() {
        return mTemplates.size();
    }

    public class RVHolder extends RecyclerView.ViewHolder {

        private final ImageView mImgRv;

        public RVHolder(View itemView) {
            super(itemView);
            mImgRv = (ImageView) itemView.findViewById(R.id.img_rv);
        }

        public void bindData(int position) {
            Template template = mTemplates.get(position);
            String imgUrl = template.getThumb_120();
            Glide.with(mContext).load(imgUrl).diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter().into(mImgRv);
        }
    }
}